import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
/**
 *
 * @param hidden 判断菜单是否在页面显示
 * @param title  菜单标题
 * @param menuType  菜单层级
 */

export const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/home",
    meta: { hidden: true, menuType: 1 },
  },
  {
    path: "/home",
    name: "home",
    meta: { title: "首页", menuType: 1, icon: "Menu" },
    component: () =>
      import(/* webpackChunkName: "home" */ "../views/home/index.vue"),
  },
  {
    path: "/vueStudy",
    name: "vueStudy",
    meta: { title: "Vue相关知识", menuType: 1, img: "vue" },
    redirect: "/vueStudy/vueComponentCommunication",
    children: [
      {
        path: "/vueStudy/vueComponentCommunication",
        name: "vueComponentCommunication",
        component: () =>
          import("@/views/vueStudy/vueComponentCommunication/index.vue"),
        meta: { title: "Vue组件通讯", menuType: 2 },
      },
      {
        path: "/vueStudy/mixin",
        name: "mixin",
        meta: { title: "Vue 混入", menuType: 2 },
        children: [
          {
            path: "/vueStudy/mixin",
            name: "mixin",
            component: () => import("@/views/vueStudy/mixin/index.vue"),
            meta: { title: "Vue2 mixin", menuType: 2 },
          },
        ],
      },
    ],
  },
  {
    path: "/jsStudy",
    name: "jsStudy",
    meta: { title: "Js相关知识", menuType: 1 },
    redirect: "/jsStudy/ajax",
    children: [
      {
        path: "/jsStudy/ajax",
        name: "ajax",
        component: () => import("@/views/jsStudy/ajax/index.vue"),
        meta: { title: "Ajax 封装", menuType: 2 },
      },
      {
        path: "/jsStudy/promise",
        name: "promise",
        component: () => import("@/views/jsStudy/promise/index.vue"),
        meta: { title: "异步(Promise)", menuType: 2 },
      },
      {
        path: "/jsStudy/numPrecision",
        name: "numPrecision",
        component: () => import("@/views/jsStudy/numPrecision.vue"),
        meta: { title: "前端数字精度问题", menuType: 2 },
      },
    ],
  },
  {
    path: "/otherFrame",
    name: "otherFrame",
    meta: { title: "其他", menuType: 1 },
    redirect: "/echarts",
    children: [
      {
        path: "/otherFrame/echarts",
        name: "echarts",
        component: () => import("@/views/otherFrame/echarts/index.vue"),
        meta: { title: "E-charts 二次封装", menuType: 2 },
      },
    ],
  },
  {
    path: "/:catchA1l(.*)",
    name: "404",
    meta: { hidden: true, menuType: 1 },
    component: () =>
      import(/* webpackChunkName: "error" */ "../views/error/index.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
